/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_ZALLOC_H
#define __COMMON_ZALLOC_H

#include <stdio.h>
#include <string.h>
#include <malloc.h>

#define Z_ALLOC_MEMORY_CATEGORIES 6
extern unsigned int _zalloc_memusage[Z_ALLOC_MEMORY_CATEGORIES];
#define Z_ALLOC_CATEGORY(c) _zalloc_memusage[c]

#define Z_ALLOC_ARGUMENT_BUFFERING 0
#define Z_ALLOC_DATA_WRAPPING 1
#define Z_ALLOC_FILE_BUFFERING 2
#define Z_ALLOC_LISTS 3
#define Z_ALLOC_DUPLICATION 4
#define Z_ALLOC_LOGGING 5

void zalloc_init(); //method: initialize zalloc/zfree system
void *zalloc(unsigned int size, unsigned int cat); //method: allocate a block of memory of size 'size' in category 'cat'.
void zfree(void *ptr); //method: free allocated block of memory

char *z_strdup(const char *s); //method: replacement for 'strdup' with zalloc/zfree
char *z_strndup(const char *s, unsigned int size); //method: replacement for 'strndup'

/// This is a malloc alternature for -_-. Memory is allocated normally, but categories are used for debugging purposes.
///
/// Available categories are as follows:
/// {{- Z_ALLOC_ARGUMENT_BUFFERING
/// - Z_ALLOC_DATA_WRAPPING
/// - Z_ALLOC_FILE_BUFFERING
/// - Z_ALLOC_LISTS
/// - Z_ALLOC_DUPLICATION
/// - Z_ALLOC_LOGGING}}

#endif